package com.jvyou.thread.d09safe1;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/30 19:29
 * @Description
 */
public class TicketThread extends Thread {

    // static 保证所有线程访问的 ticket 是同一个属性
    static int ticket = 0;

    @Override
    public void run() {
        while (true) {
            if (ticket < 100) {
                ticket++;
                System.out.println(getName() + "卖票：" + ticket);
            } else {
                break;
            }
        }
    }

    public static void main(String[] args) {
        TicketThread t1 = new TicketThread();
        t1.setName("窗口1");
        t1.start();
        TicketThread t2 = new TicketThread();
        t2.setName("窗口2");
        t2.start();
        TicketThread t3 = new TicketThread();
        t3.setName("窗口3");
        t3.start();
    }
}
